package com.garbagecan.cachestudy.oscache.simple;

import com.opensymphony.oscache.base.NeedsRefreshException;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;

public class SimpleExample {
	private GeneralCacheAdministrator cacheAdmin = new GeneralCacheAdministrator();
	public static void main(String[] args) {
		SimpleExample simple = new SimpleExample();
		simple.test1();
		simple.test2();
	}
	
	public void test1() {
		String myKey = "myKey";
		String myValue;
		
		try {
			Object obj = cacheAdmin.getFromCache(myKey);
			System.out.println(obj);
		} catch (NeedsRefreshException ex) {
			System.out.println("The cache doesn't exist!");
			cacheAdmin.cancelUpdate(myKey);
		}
	}
	
	public void test2() {
		String myKey = "myKey";
		String myValue = "=================";

		cacheAdmin.putInCache(myKey, myValue);
		try {
			Object obj = cacheAdmin.getFromCache(myKey);
			System.out.println("The cache value is: " + obj);
		} catch (NeedsRefreshException ex) {
			System.out.println("The cache doesn't exist!");
			cacheAdmin.cancelUpdate(myKey);
		}
	}
}
